﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Master.Bean;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Utils;
using Shpm.App.Input.Bean;
using Shpm.System;
using Shpm.App.Common.Dao;
using Shpm.App.Common.Bean;

public partial class App_Input_AccountPrivateForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.txtMemberNo.Attributes.Add("onblur", "showMemberInfo(this.id,'" + this.txtMemberName.ClientID + "');" );
        if (!IsPostBack)
        {
            this.tbl1.Visible = false;
            this.tbl2.Visible = false;
        }
    }
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        if (Rbtn1.Checked)
        {
            if (this.ComValidator1.DoValidator() == false)
            {

                ((Design_MasterPage)this.Master).InfoMessage = this.ComValidator1.ErrorMessage;

                return;
            }
            this.ViewState["MEMBER_NO"] = txtMemberNo.Text;
            this.ViewState["BEGIN_DATE"] = txtBeginDate.Text;
            this.ViewState["END_DATE"] = txtEndDate.Text;
            this.ViewState["COMMIT_FLG"] = drpCommitFlg.SelectedValue;

            hidMemberNo.Value = Convert.ToString(ViewState["MEMBER_NO"]);
            hidBeginDate.Value = Convert.ToString(ViewState["BEGIN_DATE"]);
            hidEndDate.Value = Convert.ToString(ViewState["END_DATE"]);
            hidCommitFlg.Value = Convert.ToString(ViewState["COMMIT_FLG"]);

            AccountPrivateBean dataBean = new AccountPrivateBean();
            AccountPrivateDao Dao = new AccountPrivateDao();
            dataBean.MemberNo = Convert.ToString(ViewState["MEMBER_NO"]);
            if (!Convert.ToString(this.ViewState["COMMIT_FLG"]).Trim().Equals(string.Empty))
            {
                if (Convert.ToString(this.ViewState["COMMIT_FLG"]) == "1")
                {
                    dataBean.CommitFlg = true;
                }
                else
                {
                    dataBean.CommitFlg = false;
                }
            }
            dataBean.BeginDate = Convert.ToDateTime(ViewState["BEGIN_DATE"]);
            dataBean.EndDate = Convert.ToDateTime(ViewState["END_DATE"]).AddDays(1);
            if (DateTime.Now > dataBean.EndDate)
            {
                dataBean.InvoiceFlg = true;
            }
            IList dataList = Dao.ListAccountPrivate(dataBean);
            if (dataList.Count > 0)
            {
                this.tbl1.Visible = true;
                this.tbl2.Visible = true;
                AccountPrivateBean apBean = new AccountPrivateBean();
                apBean = (AccountPrivateBean)dataList[0];
                lblApartmentNo.Text = apBean.ApartmentNo;
                lblMemberNo.Text = apBean.MemberNo;
                lblNameC.Text = apBean.NameC;
                //计算总额
                AccountPrivateBean sumBean = new AccountPrivateBean();
                sumBean.MemberNo = Convert.ToString(ViewState["MEMBER_NO"]);
                if (!Convert.ToString(this.ViewState["COMMIT_FLG"]).Trim().Equals(string.Empty))
                {
                    if (Convert.ToString(this.ViewState["COMMIT_FLG"]) == "1")
                    {
                        sumBean.CommitFlg = true;
                    }
                    else
                    {
                        sumBean.CommitFlg = false;
                    }
                }
                sumBean.BeginDate = Convert.ToDateTime(ViewState["BEGIN_DATE"]);
                sumBean.EndDate = Convert.ToDateTime(ViewState["END_DATE"]).AddDays(1);
                if (DateTime.Now > sumBean.EndDate)
                {
                    sumBean.InvoiceFlg = true;
                }
                IList sumdataList = Dao.SumAccountPrivate(sumBean);
                if (sumdataList.Count > 0)
                {
                    sumBean = (AccountPrivateBean)sumdataList[0];
                    lblSumAmount.Text = Convert.ToString(sumBean.SumAmount);
                }



                this.viewSrhRst.DataSource = dataList;
                this.viewSrhRst.DataBind();
            }
            else
            {
                this.tbl1.Visible = false;
                this.tbl2.Visible = false;
            }
            
            
        }
        else if (Rbtn2.Checked)
        {
            if (this.Comvalidator2.DoValidator() == false)
            {

                ((Design_MasterPage)this.Master).InfoMessage = this.Comvalidator2.ErrorMessage;

                return;
            }
            this.ViewState["CARD_NO"] = txtCardNo.Text;
            this.ViewState["BEGIN_DATE"] = txtBeginDate.Text;
            this.ViewState["END_DATE"] = txtEndDate.Text;
            this.ViewState["COMMIT_FLG"] = drpCommitFlg.SelectedValue;
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        if (Rbtn1.Checked)
        {
            
        }
        else if (Rbtn2.Checked)
        {

        }
    }
    protected void viewSrhRst_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text == "DINNER")
            {
                e.Row.Cells[1].Text = "餐饮";
            }
            else if (e.Row.Cells[1].Text == "SPECIAL")
            {
                e.Row.Cells[1].Text = "代买代办";
            }
            else if (e.Row.Cells[1].Text == "LIVING")
            {
                e.Row.Cells[1].Text = "生活内容";
            }
            else if (e.Row.Cells[1].Text == "FEE")
            {
                e.Row.Cells[1].Text = "常规费用";
            }
            if (e.Row.Cells[5].Text == "False")
            {
                e.Row.Cells[5].Text = "未付";
            }
            else if (e.Row.Cells[5].Text == "True")
            {
                e.Row.Cells[5].Text = "已付";
            }

            e.Row.Cells[4].Text = string.Format("{0:N}",Convert.ToDouble(e.Row.Cells[4].Text));
        }
    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {

    }
    protected void viewSrhRst_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        viewSrhRst.PageIndex = e.NewPageIndex;

        AccountPrivateBean dataBean = new AccountPrivateBean();
        AccountPrivateDao Dao = new AccountPrivateDao();
        dataBean.MemberNo = Convert.ToString(ViewState["MEMBER_NO"]);
        if (!Convert.ToString(this.ViewState["COMMIT_FLG"]).Trim().Equals(string.Empty))
        {
            if (Convert.ToString(this.ViewState["COMMIT_FLG"]) == "1")
            {
                dataBean.CommitFlg = true;
            }
            else
            {
                dataBean.CommitFlg = false;
            }
        }
        dataBean.BeginDate = Convert.ToDateTime(ViewState["BEGIN_DATE"]);
        dataBean.EndDate = Convert.ToDateTime(ViewState["END_DATE"]).AddDays(1);
        IList dataList = Dao.ListAccountPrivate(dataBean);
        this.viewSrhRst.DataSource = dataList;
        this.viewSrhRst.DataBind();
    }
}
